package com.ruoyi.forum.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.annotation.Anonymous;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.forum.domain.ForumCollege;
import com.ruoyi.forum.service.IForumCollegeService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 学院管理Controller
 * 
 * @author ruoyi
 * @date 2024-02-01
 */
@Api(tags="论坛-学院管理")
@RestController
@RequestMapping("/forum/college")
public class ForumCollegeController extends BaseController
{
    @Autowired
    private IForumCollegeService forumCollegeService;

    /**
     * 查询学院管理列表
     */
//    @PreAuthorize("@ss.hasPermi('forum:college:list')")
    @ApiOperation(value="分页列表查询", notes="论坛-学院管理-分页列表查询")
    @GetMapping("/list")
    @Anonymous
    public TableDataInfo list(ForumCollege forumCollege)
    {
        startPage();
        if(forumCollege.getDelFlag()==null){
            forumCollege.setDelFlag("0");
        }
        List<ForumCollege> list = forumCollegeService.selectForumCollegeList(forumCollege);
        return getDataTable(list);
    }

    /**
     *前台系统-获取所有的学院
     */
    @ApiOperation(value="分页列表查询", notes="论坛-学院管理-分页列表查询")
    @GetMapping("/briefList")
    @Anonymous
    public TableDataInfo listForQian(ForumCollege forumCollege)
    {
        if(forumCollege.getDelFlag()==null){
            forumCollege.setDelFlag("0");
        }
        List<ForumCollege> list = forumCollegeService.selectForumCollegeList(forumCollege);
        return getDataTable(list);
    }

    /**
     * 导出学院管理列表
     */
    @ApiOperation(value="导出学院管理列表", notes="论坛-学院管理-导出学院管理列表")
    @PreAuthorize("@ss.hasPermi('forum:college:export')")
    @Log(title = "学院管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ForumCollege forumCollege)
    {
        List<ForumCollege> list = forumCollegeService.selectForumCollegeList(forumCollege);
        ExcelUtil<ForumCollege> util = new ExcelUtil<ForumCollege>(ForumCollege.class);
        util.exportExcel(response, list, "学院管理数据");
    }

    /**
     * 获取学院管理详细信息
     */
    @ApiOperation(value="获取学院管理详细信息", notes="论坛-学院管理-获取学院管理详细信息")
    @PreAuthorize("@ss.hasPermi('forum:college:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(forumCollegeService.selectForumCollegeById(id));
    }

    /**
     * 新增学院管理
     */
    @ApiOperation(value="新增学院管理", notes="论坛-学院管理-新增学院管理")
    @PreAuthorize("@ss.hasPermi('forum:college:add')")
    @Log(title = "学院管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ForumCollege forumCollege)
    {
        forumCollege.setCreateBy(getUsername());
        return toAjax(forumCollegeService.insertForumCollege(forumCollege));
    }

    /**
     * 修改学院管理
     */
    @ApiOperation(value="修改学院管理", notes="论坛-学院管理-修改学院管理")
    @PreAuthorize("@ss.hasPermi('forum:college:edit')")
    @Log(title = "学院管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ForumCollege forumCollege)
    {
        forumCollege.setUpdateBy(getUsername());
        return toAjax(forumCollegeService.updateForumCollege(forumCollege));
    }

    /**
     * 删除学院管理
     */
    @ApiOperation(value="删除学院管理", notes="论坛-学院管理-删除学院管理")
    @PreAuthorize("@ss.hasPermi('forum:college:remove')")
    @Log(title = "学院管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(forumCollegeService.deleteForumCollegeByIds(ids));
    }
}
